﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Outpatient
{
    /// <summary>
    /// 门诊挂号类别
    /// </summary>
    public class OtpRgstTypeService : CrudAppService<OtpRgstType, OtpRgstTypeDto, Guid, OtpRgstTypeInput, OtpRgstTypeCreateDto, OtpRgstTypeUpdateDto>, IOtpRgstTypeService
    {
        private IRepository<OtpRgstType, Guid> _optRgstTypeRepository;

        public OtpRgstTypeService(IRepository<OtpRgstType, Guid> optRgstTypeRepository) : base(optRgstTypeRepository)
        {
            _optRgstTypeRepository = optRgstTypeRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<OtpRgstTypeDto>> GetListAsync(OtpRgstTypeInput input)
        {
            var iQuery = await _optRgstTypeRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<OtpRgstType>, List<OtpRgstTypeDto>>(iQuery.ToList());

                return new PagedResultDto<OtpRgstTypeDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<OtpRgstType>, List<OtpRgstTypeDto>>(items.ToList());

                return new PagedResultDto<OtpRgstTypeDto>(totalCount, itemsDto);
            }
        }
    }
}
